/*
 * @lc app=leetcode.cn id=1848 lang=javascript
 *
 * [1848] 到目标元素的最小距离
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} target
 * @param {number} start
 * @return {number}
 */
var getMinDistance = function (nums, target, start) {
  let i1 = nums.indexOf(target, start);
  let i2 = nums.lastIndexOf(target, start);
  if (i1 === -1) return start - i2;
  if (i2 === -1) return i1 - start;
  return Math.min(i1 - start, start - i2)
};
// @lc code=end

